package y23.Sep;

public class Test10 {
    public static void main(String[] args) {
        int[] nums1 = {1,3,5,6};
        System.out.println(searchInsert(nums1,5));
        System.out.println(searchInsert(nums1,2));
        System.out.println(searchInsert(nums1,7));
    }
    public static int searchInsert(int[] nums, int target) {
        int n = nums.length;
        int left = 0;
        int right = n - 1;
        while (left <= right) {
            int mid = ((right - left) / 2)+left;
            if (target <= nums[mid]) {
                n = mid;
                right = mid - 1;
            } else {
                left = mid + 1;
            }
        }
        return n;
    }
}
